package com.example.springsecurity.controller;

import com.example.springsecurity.common.Result;
import com.example.springsecurity.entity.User;
import com.example.springsecurity.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/user")
@Api(value = "用户功能", tags = "用户功能")
public class UserController {
    @Autowired
    UserService userService;

    @ApiOperation("用户登录")
    @PostMapping("/login")
    public Result<?> login(@RequestBody User user){
        return userService.login(user.getName(), user.getPassword());
    }

    @ApiOperation("强制下线")
    @PostMapping("/logout")
    public Result<?> logout(@ApiParam(value = "注销id",required = true) @RequestParam String id){
        return userService.logout();
    }

    @ApiOperation("用户注册")
    @PostMapping("/register")
    public Result<?> register(@RequestBody User user){
        return userService.register(user);
    }

    @ApiOperation("用户信息修改")
    @PostMapping("/update")
    public Result<?> update(@RequestBody User user){
        return userService.update(user);
    }

    @ApiOperation("用户头像")
    @PostMapping("/avatar")
    public Result<?> avatar(@RequestBody User user){
        return userService.update(user);
    }

}
